package com.hhl.flower.controller;

import com.hhl.flower.common.result.Result;
import com.hhl.flower.context.BaseContext;
import com.hhl.flower.pojo.vo.CommentVO;
import com.hhl.flower.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/comment")
@Api(tags = "用户评论相关接口")
@Slf4j
public class CommentController {
	@Autowired
	private CommentService commentService;

	@GetMapping("/list/by/user")
	@ApiOperation("查询用户所有评论")
	public Result<List<CommentVO>> listByUser(){
		Integer currentId = BaseContext.getCurrentId();

		List<CommentVO> commentVOList = commentService.listByUser(currentId);
		return Result.success(commentVOList);
	}

	@GetMapping("/list/by/flower")
	@ApiOperation("查询花卉所有评论")
	public Result<List<CommentVO>> listByFlower(@RequestParam("fid") Integer flowerId){

		List<CommentVO> commentVOList = commentService.listByFlower(flowerId);

		return Result.success(commentVOList);
	}

	@PostMapping("/add")
	@ApiOperation("添加评论")
	public Result add(@RequestParam("content") String content, @RequestParam("stars") Integer stars, @RequestParam("number") String number){
		commentService.addComment(content, stars, number);
		return Result.success();
	}

}
